{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "import * from utils\n",
    "paras_all = {}\n",
    "for rat_names, mod_names, sess_names, days in ((('R',), ('3','2','1'), ('OF','WW'), ('day1',)),\n",
    "                                               (('R',), ('3','2','1'), ('OF','REM','SWS'),('day2',)),\n",
    "                                               (('Q',), ('2','1'), ('OF','WW','REM','SWS'), ('',)),\n",
    "                                               (('S',), ('1'), ('OF','WW'), ('',))):\n",
    "    for rat_name in rat_names:\n",
    "        for mod_name in mod_names:\n",
    "            for sess_name in sess_names:                \n",
    "                for day_name in days:                \n",
    "                    if rat_name + mod_name + sess_name == 'R1SWS':\n",
    "                        sess_name += '_bursty'\n",
    "                    file_name =   rat_name + '_' + mod_name + '_' + sess_name\n",
    "                    if len(day_name)>0:\n",
    "                        file_name += '_' + day_name  \n",
    "            \n",
    "                    f = np.load('Toroidal_topology_grid_cell_data/Results/' + file_name + '_para.npz', allow_pickle = True)\n",
    "                    p1b_1 = f['p1b_1']\n",
    "                    p2b_1 = f['p2b_1']\n",
    "                    xedge = f['xedge']\n",
    "                    yedge = f['yedge']\n",
    "                    m1b_1 = f['m1b_1']\n",
    "                    m2b_1 = f['m2b_1']\n",
    "                    f.close()\n",
    "\n",
    "                    x,y = rot_para(p1b_1,p2b_1)\n",
    "                    xmin = xedge.min()\n",
    "                    xedge -= xmin\n",
    "                    xmax = xedge.max()\n",
    "                    ymin = yedge.min()\n",
    "                    yedge -= ymin\n",
    "                    ymax = yedge.max()\n",
    "                    paras_all[file_name] = (((y[0]-x[0])/(2*np.pi)*360)%360, 1/x[2]*xmax, 1/y[2]*ymax)\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:478: RuntimeWarning: divide by zero encountered in log2\n",
      "C:\\Users\\erihe\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:479: RuntimeWarning: invalid value encountered in multiply\n"
     ]
    }
   ],
   "source": [
    "numbins = 15\n",
    "bins = np.linspace(0,1, numbins+1)\n",
    "noisestd = (1.5/len_scale)*2.*np.pi\n",
    "sigma = 1500\n",
    "for rat_name, mod_name, sess_name, day_name in (('R', '1', 'OF', 'day1'),\n",
    "                                                ('R', '2', 'OF', 'day1'),\n",
    "                                                ('R', '3', 'OF', 'day1'),\n",
    "                                                ('R', '1', 'WW', 'day1'),\n",
    "                                                ('R', '2', 'WW', 'day1'),\n",
    "                                                ('R', '3', 'WW', 'day1'),\n",
    "                                                ('R', '1', 'OF', 'day2'),\n",
    "                                                ('R', '2', 'OF', 'day2'),\n",
    "                                                ('R', '3', 'OF', 'day2'),\n",
    "                                                ('Q', '1', 'OF', ''),\n",
    "                                                ('Q', '2', 'OF', ''),\n",
    "                                                ('Q', '1', 'WW', ''),\n",
    "                                                ('Q', '2', 'WW', ''),\n",
    "                                                ('S', '1', 'OF', ''),\n",
    "                                                ('S', '1', 'WW', ''),\n",
    "                                                ):\n",
    "    file_name =  rat_name + '_' + mod_name + '_' + sess_name\n",
    "    if len(day_name)>0:\n",
    "        file_name += '_' + day_name  \n",
    "        \n",
    "    len_scale = (paras_all[file_name][1] + paras_all[file_name][2])/2*100\n",
    "    noisestd = (1.5/len_scale)*2.*np.pi\n",
    "\n",
    "    sspikes,xx,yy,__,__ = get_spikes(rat_name, mod_name, day_name, sess_name, bType = 'pure',\n",
    "                                     bSmooth = True, bSpeed = True, smoothing_width = sigma)\n",
    "    spikes,__,__,__,__ = get_spikes(rat_name, mod_name, day_name, sess_name, bType = 'pure',\n",
    "                                     bSmooth = False, bSpeed = True)\n",
    "\n",
    "    T, num_neurons  = np.shape(sspikes)\n",
    "    I_torus = np.zeros(num_neurons)\n",
    "    I_space = np.zeros(num_neurons)    \n",
    "    ############################## Load 1 ############################\n",
    "    f = np.load('Toroidal_topology_grid_cell_data/Results/' + file_name  + '_decoding.npz', allow_pickle = True)\n",
    "    centcosall = f['centcosall']\n",
    "    centsinall = f['centsinall']\n",
    "    times = f['times']\n",
    "    f.close()    \n",
    "\n",
    "    dspk = preprocessing.scale(sspikes[:,:]).copy()\n",
    "    a = np.zeros((T, 2, num_neurons))\n",
    "    for n in range(num_neurons):\n",
    "        a[:,:,n] = np.multiply(dspk[:,n:n+1],np.sum(centcosall[n,:,:],1))\n",
    "\n",
    "    c = np.zeros((T, 2, num_neurons))\n",
    "    for n in range(num_neurons):\n",
    "        c[:,:,n] = np.multiply(dspk[:,n:n+1],np.sum(centsinall[n,:,:],1))\n",
    "\n",
    "    coordsall = {}\n",
    "    xx = preprocessing.minmax_scale(xx)\n",
    "    yy = preprocessing.minmax_scale(yy)\n",
    "    for n in range(num_neurons):\n",
    "        inds = np.ones(len(sspikes[0,:]))\n",
    "        inds[n] = 0\n",
    "        inds = np.where(inds)[0]\n",
    "\n",
    "        mtot2 = np.sum(c[:,:,inds],2)\n",
    "        mtot1 = np.sum(a[:,:,inds],2)\n",
    "\n",
    "        coords = np.arctan2(mtot2,mtot1)%(2*np.pi)\n",
    "        coords = preprocessing.minmax_scale((coords+np.random.normal(0, noisestd, np.shape(coords)))%(2*np.pi))\n",
    "        \n",
    "        spkmean = spikes[times,n].mean()\n",
    "        mtot5, x_edge, y_edge, c5 = binned_statistic_2d(coords[times,0],coords[times,1], \n",
    "                                                        spikes[times,n], statistic = 'mean', bins=bins, \n",
    "                                                        range=None, expand_binnumbers=True)   \n",
    "        I_torus[n] = information_score(mtot5.copy(), c5, spkmean)/spkmean        \n",
    "        mtot5, x_edge, y_edge, c5 = binned_statistic_2d(xx[times],yy[times],\n",
    "                                                        spikes[times,n], statistic = 'mean', bins=bins, \n",
    "                                                        range=None, expand_binnumbers=True)                    \n",
    "        I_space[n] = information_score(mtot5.copy(), c5, spkmean)/spkmean\n",
    "        coordsall[n] = coords\n",
    "    np.savez_compressed('Toroidal_topology_grid_cell_data/Results/' + file_name + '_info', \n",
    "                        I_torus = I_torus, I_space = I_space)\n",
    "    np.savez_compressed('Toroidal_topology_grid_cell_data/Results/' + file_name + '_coords', \n",
    "                        coordsall = coordsall, times = times, force_zip64=True)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "    np.savez_compressed('Toroidal_topology_grid_cell_data/Results/' + file_name + '_info', \n",
    "                        I_torus = I_torus, I_space = I_space)\n",
    "    np.savez_compressed('Toroidal_topology_grid_cell_data/Results/' + file_name + '_coords', \n",
    "                        coordsall = coordsall, times = times)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for rat_name, mod_name, sess_name, day_name in (('R', '1', 'REM', 'day2'),\n",
    "                                                ('R', '2', 'REM', 'day2'),\n",
    "                                                ('R', '3', 'REM', 'day2'),\n",
    "                                                ('R', '1', 'SWS', 'day2'),\n",
    "                                                ('R', '2', 'SWS', 'day2'),\n",
    "                                                ('R', '3', 'SWS', 'day2'),\n",
    "                                                ('Q', '1', 'REM', ''),\n",
    "                                                ('Q', '2', 'REM', ''),\n",
    "                                                ('Q', '1', 'SWS', ''),\n",
    "                                                ('Q', '2', 'SWS', ''),\n",
    "                                                ('S', '1', 'REM', ''),\n",
    "                                                ('S', '1', 'SWS', '')\n",
    "                                                ):\n",
    "    sspikes,xx,yy,__,__ = get_spikes(rat_name, mod_name, day_name, sess_name, bType = 'pure',\n",
    "                                     bSmooth = True, bSpeed = True, smoothing_width = sigma)\n",
    "    spikes = get_spikes(rat_name, mod_name, day_name, sess_name, bType = 'pure', bSmooth = False, bSpeed = False)\n",
    "\n",
    "    T, num_neurons  = np.shape(sspikes)\n",
    "\n",
    "    I_torus = np.zeros(num_neurons)\n",
    "    bins = np.linspace(0,2*np.pi, numbins+1)\n",
    "\n",
    "    f = np.load('Data/' + file_name + '_newdecoding.npz', allow_pickle = True)\n",
    "    centcosall = f['centcosall']\n",
    "    centsinall = f['centsinall']\n",
    "    times = f['times']\n",
    "    f.close()\n",
    "\n",
    "    dspk = preprocessing.scale(sspikes[:,:]).copy()\n",
    "    a = np.zeros((T, 2, num_neurons))\n",
    "    for n in range(num_neurons):\n",
    "        a[:,:,n] = np.multiply(dspk[:,n:n+1],np.sum(centcosall[n,:,:],1))\n",
    "\n",
    "    c = np.zeros((T, 2, num_neurons))\n",
    "    for n in range(num_neurons):\n",
    "        c[:,:,n] = np.multiply(dspk[:,n:n+1],np.sum(centsinall[n,:,:],1))\n",
    "\n",
    "    coordsall = {}\n",
    "    for n in range(num_neurons):\n",
    "        inds = np.ones(len(sspikes[0,:]))\n",
    "        inds[n] = 0\n",
    "        inds = np.where(inds)[0]\n",
    "\n",
    "        mtot2 = np.sum(c[:,:,inds],2)\n",
    "        mtot1 = np.sum(a[:,:,inds],2)\n",
    "\n",
    "        coords = np.arctan2(mtot2,mtot1)%(2*np.pi)\n",
    "\n",
    "        mtot5, x_edge, y_edge, c5 = binned_statistic_2d(coords[times,0],coords[times,1], \n",
    "                spikes[times,n], statistic = 'mean', bins=bins, range=None, expand_binnumbers=True)            \n",
    "        spkmean = spikes[times,n].mean()\n",
    "        I_torus[n] = information_score(mtot5.copy(), c5, spkmean)/spkmean\n",
    "        coordsall[str(n)] = coords\n",
    "    np.savez_compressed('Toroidal_topology_grid_cell_data/Results/' + file_name + '_info', \n",
    "                        I_torus = I_torus)\n",
    "    np.savez_compressed('Toroidal_topology_grid_cell_data/Results/' + file_name + '_coords', \n",
    "                        coordsall = coordsall, force_zip64=True)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "R_1_OF\n",
      " n: 93\n",
      " p: WilcoxonResult(statistic=3576.0, pvalue=4.969637217118854e-08)\n",
      "\n"
     ]
    },
    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Y2X+XKFPq15VXMBFv0kS8ls+b2TKyEwfvJ9vakThm9j2ytf4nm9ku4EvADAB3/xawnmxN+gAwAny6PiWdWoRr+QTwWTMbBd4Flif0H6GLgRXAdjPLLWV3K3AaTP/vom7ZIlJSGl43RKSOFBIiUpJCQkRKUkiISEkKCREpSSEhIiUpJESkJIWEiJT0/wE8eyDS7mbFUQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from scipy.stats import wilcoxon\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.add_subplot(111)\n",
    "minEV = np.inf\n",
    "maxEV = -np.inf\n",
    "\n",
    "Information_rate_Toroidal_OF = []\n",
    "Information_rate_Spatial_OF = []\n",
    "\n",
    "for rat_name, mod_name, sess_name, day_name in (('R', '1', 'OF', 'day1'),\n",
    "                                                #('R', '2', 'OF', 'day1'),\n",
    "                                                #('R', '3', 'OF', 'day1'),\n",
    "                                                #('R', '1', 'OF', 'day2'),\n",
    "                                                #('R', '2', 'OF', 'day2'),\n",
    "                                                #('R', '3', 'OF', 'day2'),\n",
    "                                                #('Q', '1', 'OF', ''),\n",
    "                                                #('Q', '2', 'OF', ''),\n",
    "                                                #('S', '1', 'OF', ''),\n",
    "                                               ):            \n",
    "            file_name = rat_name + '_' + mod_name + '_' + sess_name\n",
    "            f = np.load('Toroidal_topology_grid_cell_data/Results/' + file_name + '_info.npz', allow_pickle = True)\n",
    "            torscores = f['I_torus']\n",
    "            spacescores = f['I_space']\n",
    "            f.close()\n",
    "\n",
    "            maxEV =  max(maxEV, max(np.max(torscores), np.max(spacescores)))\n",
    "            minEV =  min(minEV, min(np.min(torscores), np.min(spacescores)))\n",
    "            ax.scatter(spacescores, torscores, s = 10, c = colors_envs[file_name])\n",
    "            p  = wilcoxon(torscores-spacescores, alternative='greater')\n",
    "            print(file_name)\n",
    "            print(' n: ' + str(len(torscores)) )\n",
    "            print(' p: ' + str(p) )\n",
    "            print('')\n",
    "\n",
    "            Information_rate_Toroidal_OF.extend([np.mean(torscores)])\n",
    "            Information_rate_Toroidal_OF.extend([np.std(torscores)/np.sqrt(len(torscores))])\n",
    "            Information_rate_Spatial_OF.extend([np.mean(spacescores)])\n",
    "            Information_rate_Spatial_OF.extend([np.std(spacescores)/np.sqrt(len(spacescores))])\n",
    "ax.plot([minEV, maxEV], [minEV, maxEV], c='k', zorder = -5)\n",
    "ax.set_xlim([minEV-(maxEV-minEV)*0.05,maxEV+(maxEV-minEV)*0.05])\n",
    "ax.set_ylim([minEV-(maxEV-minEV)*0.05,maxEV+(maxEV-minEV)*0.05])\n",
    "ax.set_aspect('equal', 'box')\n",
    "ax.xaxis.set_tick_params(width=1, length =5)\n",
    "ax.yaxis.set_tick_params(width=1, length =5)\n",
    "\n",
    "plot_stats(Information_rate_Toroidal_OF, Information_rate_Spatial_OF,  \n",
    "    Information_rate_OF_lbls, 'info', 'OF')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from scipy.stats import wilcoxon\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.add_subplot(111)\n",
    "minEV = np.inf\n",
    "maxEV = -np.inf\n",
    "\n",
    "Information_rate_Toroidal_C = []\n",
    "Information_rate_Spatial_C = []\n",
    "\n",
    "for rat_name, mod_name, sess_name, day_name in (('R', '1', 'WW', 'day1'),\n",
    "                                                ('R', '2', 'WW', 'day1'),\n",
    "                                                ('R', '3', 'WW', 'day1'),\n",
    "                                                ('Q', '1', 'WW', ''),\n",
    "                                                ('Q', '2', 'WW', ''),\n",
    "                                                ('S', '1', 'WW', ''),\n",
    "                                               ):            \n",
    "            file_name = rat_name + '_' + mod_name + '_' + sess_name\n",
    "            f = np.load('Toroidal_topology_grid_cell_data/Results/' + file_name + '_info.npz', allow_pickle = True)\n",
    "            torscores = f['I_torus']\n",
    "            spacescores = f['I_space']\n",
    "            f.close()\n",
    "\n",
    "            maxEV =  max(maxEV, max(np.max(torscores), np.max(spacescores)))\n",
    "            minEV =  min(minEV, min(np.min(torscores), np.min(spacescores)))\n",
    "            ax.scatter(spacescores, torscores, s = 10, c = colors_envs[file_name])\n",
    "            p  = wilcoxon(torscores-spacescores, alternative='greater')\n",
    "            print(file_name)\n",
    "            print(' n: ' + str(len(torscores)) )\n",
    "            print(' p: ' + str(p) )\n",
    "            print('')\n",
    "\n",
    "            Information_rate_Toroidal_C.extend([np.mean(torscores)])\n",
    "            Information_rate_Toroidal_C.extend([np.std(torscores)/np.sqrt(len(torscores))])\n",
    "            Information_rate_Spatial_C.extend([np.mean(spacescores)])\n",
    "            Information_rate_Spatial_C.extend([np.std(spacescores)/np.sqrt(len(spacescores))])\n",
    "ax.plot([minEV, maxEV], [minEV, maxEV], c='k', zorder = -5)\n",
    "ax.set_xlim([minEV-(maxEV-minEV)*0.05,maxEV+(maxEV-minEV)*0.05])\n",
    "ax.set_ylim([minEV-(maxEV-minEV)*0.05,maxEV+(maxEV-minEV)*0.05])\n",
    "ax.set_aspect('equal', 'box')\n",
    "ax.xaxis.set_tick_params(width=1, length =5)\n",
    "ax.yaxis.set_tick_params(width=1, length =5)\n",
    "plot_stats(Information_rate_Toroidal_C, Information_rate_Spatial_C,  \n",
    "    Information_rate_C_lbls, 'info', 'C')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "###################### histogram information content SWS\n",
    "\n",
    "import h5py\n",
    "import numpy as np \n",
    "from ripser import Rips, ripser\n",
    "from sklearn import preprocessing\n",
    "from scipy.spatial.distance import cdist, pdist, squareform\n",
    "from scipy.ndimage import gaussian_filter1d, gaussian_filter\n",
    "from scipy.sparse import coo_matrix\n",
    "from scipy.linalg import eigh\n",
    "from scipy.sparse.linalg import lsmr\n",
    "from datetime import datetime \n",
    "import time\n",
    "import sys\n",
    "import numba\n",
    "import matplotlib\n",
    "import matplotlib.pyplot as plt\n",
    "from utils import *\n",
    "\n",
    "rat_names = ['roger', 'quentin']\n",
    "#rat_names = ['quentin']\n",
    "mod_names = ['mod1', 'mod2', 'mod3']\n",
    "sess_names = ['sws']\n",
    "#LAMs = [10]#,10,100,1000]\n",
    "Lams = np.array([1,10,100,1000])\n",
    "Lams = np.sqrt(Lams).astype(int)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.add_subplot(111)\n",
    "minEV = np.inf\n",
    "maxEV = -np.inf\n",
    "colors_envs['roger_mod1_box_rec2'] = [[0.7,0.3,0.3]]\n",
    "colors_envs['roger_mod2_box_rec2'] = [[0.7,0.7,0]]\n",
    "colors_envs['roger_mod3_box_rec2'] = [[0.7,0.,0.7]]\n",
    "\n",
    "lins = np.linspace(0,2.5,10)#np.arange(0.0,4,0.25)\n",
    "print(lins)\n",
    "numbins = len(lins)\n",
    "width = (lins[1]-lins[0])/2\n",
    "b1_max = -np.inf\n",
    "\n",
    "torscoresall = []\n",
    "spacescoresall = []\n",
    "nils = 0 \n",
    "j = 0\n",
    "I_mean =  np.zeros(4)\n",
    "for rat_name, mod_name, sess_name, day_name in (('R', '1', 'REM', 'day2'),\n",
    "                                                ('R', '2', 'REM', 'day2'),\n",
    "                                                ('R', '3', 'REM', 'day2'),\n",
    "                                                ('R', '1', 'SWS', 'day2'),\n",
    "                                                ('R', '2', 'SWS', 'day2'),\n",
    "                                                ('R', '3', 'SWS', 'day2'),\n",
    "                                                ('Q', '1', 'REM', ''),\n",
    "                                                ('Q', '2', 'REM', ''),\n",
    "                                                ('Q', '1', 'SWS', ''),\n",
    "                                                ('Q', '2', 'SWS', ''),\n",
    "                                                ('S', '1', 'REM', ''),\n",
    "                                                ('S', '1', 'SWS', '')\n",
    "                                                ):\n",
    "        file_name = rat_name + '_' + mod_name + '_' + sess_name\n",
    "        f = np.load('Toroidal_topology_grid_cell_data/Results/' + file_name + '_info.npz', allow_pickle = True)\n",
    "        torscores = f['I_torus']\n",
    "        f.close()\n",
    "        maxEV =  max(maxEV, np.max(torscores))\n",
    "        minEV =  min(minEV, np.min(torscores))\n",
    "        i1 = np.digitize(torscores, lins)-1\n",
    "        b1 = np.bincount(i1,minlength = numbins)/len(torscores,)\n",
    "        b1_max = max(b1_max,np.max(b1))\n",
    "        ax.plot(lins + width, b1,  alpha = 0.7, c = colors_envs[file_name][0], lw = 3)\n",
    "        I_mean[j] = np.mean(I_torus_sws_shuf)\n",
    "        j += 1\n",
    "\n",
    "\n",
    "b1_max = 0.4\n",
    "\n",
    "ax.plot([np.mean(I_mean),np.mean(I_mean)], [0, b1_max], c = 'k', ls = '--', lw = 1 )\n",
    "\n",
    "ax.set_ylim([0,b1_max])\n",
    "ax.set_xlim([np.min(lins),np.max(lins)])\n",
    "ax.spines['top'].set_visible(False)\n",
    "ax.spines['right'].set_visible(False)\n",
    "ax.set_xticks([0,0.5,1,1.5,2,2.5])\n",
    "ax.set_xticklabels(('','','','','',''))\n",
    "ax.xaxis.set_tick_params(width=1, length =5)\n",
    "ax.set_yticks([0,0.1,0.2,0.3])\n",
    "ax.set_yticklabels(('','','',''))\n",
    "ax.yaxis.set_tick_params(width=1, length =5)            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "###################### histogram information content SWS\n",
    "\n",
    "import h5py\n",
    "import numpy as np \n",
    "from ripser import Rips, ripser\n",
    "from sklearn import preprocessing\n",
    "from scipy.spatial.distance import cdist, pdist, squareform\n",
    "from scipy.ndimage import gaussian_filter1d, gaussian_filter\n",
    "from scipy.sparse import coo_matrix\n",
    "from scipy.linalg import eigh\n",
    "from scipy.sparse.linalg import lsmr\n",
    "from datetime import datetime \n",
    "import time\n",
    "import sys\n",
    "import numba\n",
    "import matplotlib\n",
    "import matplotlib.pyplot as plt\n",
    "from utils import *\n",
    "\n",
    "rat_names = ['roger', 'quentin']\n",
    "#rat_names = ['quentin']\n",
    "mod_names = ['mod1', 'mod2', 'mod3']\n",
    "sess_names = ['sws']\n",
    "#LAMs = [10]#,10,100,1000]\n",
    "Lams = np.array([1,10,100,1000])\n",
    "Lams = np.sqrt(Lams).astype(int)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.add_subplot(111)\n",
    "minEV = np.inf\n",
    "maxEV = -np.inf\n",
    "colors_envs['roger_mod1_box_rec2'] = [[0.7,0.3,0.3]]\n",
    "colors_envs['roger_mod2_box_rec2'] = [[0.7,0.7,0]]\n",
    "colors_envs['roger_mod3_box_rec2'] = [[0.7,0.,0.7]]\n",
    "\n",
    "lins = np.linspace(0,2.5,10)#np.arange(0.0,4,0.25)\n",
    "print(lins)\n",
    "numbins = len(lins)\n",
    "width = (lins[1]-lins[0])/2\n",
    "b1_max = -np.inf\n",
    "\n",
    "torscoresall = []\n",
    "spacescoresall = []\n",
    "nils = 0 \n",
    "j = 0\n",
    "I_mean =  np.zeros(4)\n",
    "for rat_name, mod_name, sess_name, day_name in (('R', '1', 'REM', 'day2'),\n",
    "                                                ('R', '2', 'REM', 'day2'),\n",
    "                                                ('R', '3', 'REM', 'day2'),\n",
    "                                                ('Q', '1', 'REM', ''),\n",
    "                                                ('Q', '2', 'REM', ''),\n",
    "                                                ('S', '1', 'REM', ''),\n",
    "                                                ):\n",
    "        file_name = rat_name + '_' + mod_name + '_' + sess_name\n",
    "        f = np.load('Toroidal_topology_grid_cell_data/Results/' + file_name + '_info.npz', allow_pickle = True)\n",
    "        torscores = f['I_torus']\n",
    "        f.close()\n",
    "        maxEV =  max(maxEV, np.max(torscores))\n",
    "        minEV =  min(minEV, np.min(torscores))\n",
    "        i1 = np.digitize(torscores, lins)-1\n",
    "        b1 = np.bincount(i1,minlength = numbins)/len(torscores,)\n",
    "        b1_max = max(b1_max,np.max(b1))\n",
    "        ax.plot(lins + width, b1,  alpha = 0.7, c = colors_envs[file_name][0], lw = 3)\n",
    "        I_mean[j] = np.mean(I_torus_sws_shuf)\n",
    "        j += 1\n",
    "\n",
    "\n",
    "b1_max = 0.4\n",
    "\n",
    "ax.plot([np.mean(I_mean),np.mean(I_mean)], [0, b1_max], c = 'k', ls = '--', lw = 1 )\n",
    "\n",
    "ax.set_ylim([0,b1_max])\n",
    "ax.set_xlim([np.min(lins),np.max(lins)])\n",
    "ax.spines['top'].set_visible(False)\n",
    "ax.spines['right'].set_visible(False)\n",
    "ax.set_xticks([0,0.5,1,1.5,2,2.5])\n",
    "ax.set_xticklabels(('','','','','',''))\n",
    "ax.xaxis.set_tick_params(width=1, length =5)\n",
    "ax.set_yticks([0,0.1,0.2,0.3])\n",
    "ax.set_yticklabels(('','','',''))\n",
    "ax.yaxis.set_tick_params(width=1, length =5)            \n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
